// pages/component/component.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [
      {
        id: 0,
        name: '首页',
        isActive: true
      },
      {
        id: 1,
        name: '原创',
        isActive: false
      },
      {
        id: 2,
        name: '分类',
        isActive: false
      },
      {
        id: 3,
        name: '关于',
        isActive: false
      }
    ],
    titles: [
      {
        id: 0,
        name: '流行',
        isActive: true
      },
      {
        id: 1,
        name: '新款',
        isActive: false
      },
      {
        id: 2,
        name: '精选',
        isActive: false
      },
      {
        id: 3,
        name: '帽子',
        isActive: false
      }
    ],
    counter: 0
  },
  //自定义事件
  handItemChange(e) {
    const index = e.detail.index
    let tabs = this.data.tabs
    tabs.forEach((v,i) => {
      i===index?v.isActive=true:v.isActive=false
    });
    this.setData({
      tabs
    })
  },
  handleincrement(event) {
    const {name, age} = event.detail
    console.log(name, age);
    this.setData({
      counter: this.data.counter + 1
    })
  },
  handlesubstract(event) {
    const name = event.detail.name
    console.log(name);
    this.setData({
      counter: this.data.counter - 1
    })
  },
  handleTabItemClick(event) {
    const index = event.detail.index
    let titles2 = this.data.titles
    titles2.forEach((v, i) => {
      i === index? v.isActive=true:v.isActive=false
    })
    this.setData({
      titles: titles2
    })
  },
  handleIncrementCpn() {
    const mySel = this.selectComponent('#mySel')
    // mySel.setData({
    //   counter: mySel.data.counter + 1
    // })
    mySel.incrementCounter(11)
  },
})